// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_MST_CUSTOMER
// * CreateDate    : 2013-08-28 11:00:56
// * Creater       : CodeSmith
// * LastChangeDate: 2013-08-28 11:00:56
// * LastChanger   : 2013-08-28 11:00:56
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;

namespace ESOL.Business.Mst
{
/// <summary>
    /// MstCustomer
    /// </summary>
    public partial class MstCustomerBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objMstCustomerEntity">Entity</param>
        /// <returns>Entity</returns>
        public static MstCustomerEntity GetMstCustomer(MstCustomerEntity objMstCustomerEntity)
        {
            return DataAccess.SelectSingle<MstCustomerEntity>(objMstCustomerEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objMstCustomerEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertMstCustomer(MstCustomerEntity objMstCustomerEntity)
        {
            return DataAccess.Insert(objMstCustomerEntity);
        }

        public static bool InsertMstCustomer(List<MstCustomerEntity> objMstCustomerEntityList)
        {
            return DataAccess.Insert(objMstCustomerEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objMstCustomerEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateMstCustomer(MstCustomerEntity objMstCustomerEntity)
        {
            return DataAccess.Update(objMstCustomerEntity);
        }

        public static bool UpdateMstCustomer(List<MstCustomerEntity> objMstCustomerEntityList)
        {
            return DataAccess.Update<MstCustomerEntity>(objMstCustomerEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objMstCustomerEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteMstCustomer(MstCustomerEntity objMstCustomerEntity)
        {
            return DataAccess.Delete(objMstCustomerEntity);
        }

        public static bool DeleteMstCustomer(List<MstCustomerEntity> objMstCustomerEntityList)
        {
            return DataAccess.Delete<MstCustomerEntity>(objMstCustomerEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetMstCustomerAll()
        {
            return DataAccess.SelectAllDataSet<MstCustomerEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<MstCustomerEntity> GetMstCustomerAllList()
        {
            return DataAccess.SelectAll<MstCustomerEntity>();
        }
        #endregion


        #region Func
        public static DataSet GetCustomerByCondition(string condition)
        {
            string sql = @"select D.*,B.*,C.*, CC.CONTACT_NAME AS MAIN_CONTACT_NAME, CC.CONTACT_MOBILEPHONE AS MAIN_CONTACT_MOBILEPHONE
						FROM MST_CUSTOMER D 
						LEFT JOIN MST_INDUSTRY_TYPE B on D.INDUSTRY_TYPE_CODE=B.INDUSTRY_TYPE_CODE  
						LEFT JOIN MST_COMMON_ITEM C ON D.[LEVEL]=C.ITEM_CODE
						LEFT JOIN (SELECT CUSTOMER_ID,MAX(CONTACT_NAME) AS CONTACT_NAME, MAX(CONTACT_MOBILEPHONE) AS CONTACT_MOBILEPHONE 
							FROM MST_CUSTOMER_CONTACT WHERE CONTACT_LEVEL = 'CLEVEL01' GROUP BY CUSTOMER_ID) CC ON CC.CUSTOMER_ID = D.CUSTOMER_ID
                        WHERE D.STATUS != 'STATUS05' ";
            if (string.IsNullOrEmpty(condition) == false)
            {
                sql += condition;
            }
            return DataAccess.SelectDataSet(sql);
        }
        #endregion
    }
	
	
}	

